package demo516;


import java.util.List;
import java.util.Scanner;

public class TestList {
    //1

    public void addEmp(List<Emp> list, Emp emp) {

        list.add(emp);
    }
//2
    // public void findAllEmp(List<Emp> list) {
    //   for (int i = 0; i < list.size(); i++) {
    //     System.out.println(list.get(i));
    //}
    //}
    public void findAllEmp(List<Emp> list) {
          for (Emp emp:list) {
            System.out.println(emp);
        }
    }

//3
    public Emp findEmpName(List<Emp> list, String empName) {
        for (Emp emp:list) {
            if (empName.equals(emp.getName())) {
                return emp;
            }
        }
        return null;
    }
//4
    public void deleteEmp(List<Emp> list, String empNumber) {
        for (int i = 0; i < list.size(); i++) {
            if (empNumber.equals(list.get(i).getNumber())) {
                list.remove(i);
            }
        }
    }

//5
    public Emp findEmpNumber(List<Emp> list, String empNumber) {
        for (Emp emp:list) {
            if (empNumber.equals(emp.getNumber())) {
                return emp;
            }
        }
        return null;
    }
//6
    public Emp ListEmp(List<Emp> list, Emp emp) {
        for (int i = 0; i < list.size(); i++) {
            if (emp.getNumber().equals(list.get(i).getName())) {
                list.set(i,emp);
            }
        }

        return emp;
    }
}
